// packageB/pages/package/pfep/standard_query/incoming_packing_standard/incoming_packing_standard.js
const mybehavior = require("../../../../../../behaviors/requests")
import Dialog from '@vant/weapp/dialog/dialog';
Page({
  /**
   * 页面的初始数据
   */
  behaviors: [mybehavior],
  data: {
    baseUrl: "https://logisticsengineering.gree.com/pfep2_api",
    page: 1,
    page_size: 5,
    query_cond: {},
    tb_key: "",
    permission_list: [],
    show: false,
    activeNames: ['1'],
    activeNames1: [],
    show_list: [],
    previewImageClick: false,
    row_data: {},
    record_show: false,
    steps: [],
    active: 0,
    ronqi_list: [],
    fucai_list: [],
    popup_show1: false,
    popup_show2: false,
    popup_show3: false,

  },
  // 预览照片
  previewPhoto(e) {
    console.log(e.currentTarget.dataset);
    let arr = e.currentTarget.dataset.row_data
    let current_img = e.currentTarget.dataset.current_img
    let u = []
    for (let i in arr) {
      let img_url = "https://logisticsengineering.gree.com/pfep2_api/photo_manage/fs_download?file_id=" + arr[i].file_id
      // console.log(img_url);
      u.push(img_url)
    }

    wx.previewImage({
      current: current_img,
      urls: u,
    })
  },


  // 获取数据
  getDatas(e) {

    let url = this.data.baseUrl + "/standard_doc_store_manage/query_standard_doc_store"
    let data = {
      page: 1,
      page_size: 1,
      query_cond: e,
      tb_key: "",
    }
    console.log("avbasfsa", data);
    this.post(url, data).then(res => {
      console.log("获取数据", res.data.results)
      let data_list = res.data.results


      if (res.code == 20000) {

        this.setData({
          row_data: data_list[0].content,
          previewImageClick: true

        })
        console.log("sdgasdfghdfh", this.data.row_data);

      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },

  // 获取--供应商--数据
  getPermissionDatas() {
    let url = this.data.baseUrl + "/data_auth_manage/get_u_permission"
    let data = {

    }
    this.post(url, data).then(res => {
      console.log("获取供应商数据", res.data)
      let data_list = Object.keys(res.data)
      // console.log("xxx", data_list);

      if (res.code == 20000) {

        this.setData({
          permission_list: data_list,
          previewImageClick: true

        })

      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 获取--容器库--数据
  getRonqisDatas() {
    let url = this.data.baseUrl + "/container_manage/query_containers"
    let data = {
      page: 1,
      page_size: 9999,
      query_cond: {
        "content.database": "容器库"
      },
    }
    this.post(url, data).then(res => {
      // console.log("获取--容器库--数据", res.data.results)
      let res_list = res.data.results
      let list1 = []
      for (let i in res_list) {
        list1.push(res_list[i].content)
      }
      console.log(list1);
      if (res.code == 20000) {
        this.setData({
          ronqi_list: list1,
          previewImageClick: true

        })

      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },
  // 获取--辅材库--数据
  getFucaiDatas() {
    let url = this.data.baseUrl + "/container_manage/query_containers"
    let data = {
      page: 1,
      page_size: 9999,
      query_cond: {
        "content.database": "辅材库"
      },
    }
    this.post(url, data).then(res => {
      // console.log("获取--辅材库--数据", res.data.results)
      let res_list = res.data.results
      let list1 = []
      for (let i in res_list) {
        list1.push(res_list[i].content)
      }
      console.log(list1);
      if (res.code == 20000) {
        this.setData({
          fucai_list: list1,
          previewImageClick: true

        })

      } else {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
      }
    }).catch(err => {
      console.log(err);
      wx.showToast({
        title: err.msg,
        icon: 'none'
      })
    })
  },

  // 折叠面板
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  // 折叠面板
  onChange1(event) {
    this.setData({
      activeNames1: event.detail,
    });
  },

  // 点击--适用单位--选取输入框
  onClick1(event) {
    // event.detail 为当前输入的值
    // console.log(event.detail);
    this.setData({
      popup_show1: true
    })
  },
  // 选择--适用单位--输入框关闭
  onClose11() {
    this.setData({ popup_show1: false });
  },
  // 确认--适用单位--值--弹出框关闭
  onChange11(event) {
    const { picker, value, index } = event.detail;
    this.setData({
      "row_data.infoData.apply_unit": value,
      popup_show1: false,
    })
  },

  // 点击--适用单位--选取输入框
  onClick12(event) {
    // event.detail 为当前输入的值
    // console.log(event.detail);
    this.setData({
      popup_show2: true
    })
  },
  // 选择--适用单位--输入框关闭
  onClose12() {
    this.setData({ popup_show2: false });
  },
  // 确认--适用单位--值--弹出框关闭
  onChange12(event) {
    const { picker, value, index } = event.detail;
    console.log(value);
    this.setData({
      // "row_data.infoData.apply_unit": value,
      popup_show1: false,
    })
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let self = this
    const eventChannel = this.getOpenerEventChannel()
    // 监听acceptDataFromOpenerPage事件，获取上一页面通过eventChannel传送到当前页面的数据
    eventChannel.on('acceptDataFromOpenerPage', function (data) {
      console.log("传过来的数据", data)
      self.setData({
        row_data: data.content
      })


    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {


  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})